package com.treasure.mall.biz.entity.embeddable;

import com.treasure.mall.biz.entity.product.ProductPO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.math.BigDecimal;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/7/23
 */
@Embeddable
@Setter
@Getter
@NoArgsConstructor
public class Product {
    @Column(name = "product_id")
    private Long productId;
    @Column(name = "product_name")
    private String productName;
    @Column(name = "category_id")
    private Long categoryId;
    @Column(name = "cate_name")
    private String cateName;
    /**
     * 零售价格
     */
    @Column(name = "price", scale = 2, precision = 10)
    private BigDecimal price;
    /**
     * 商品缩略图
     */
    @Column(name = "thumbnail")
    private String thumbnail;

    public Product(ProductPO productPO) {
        this.productId = productPO.getProductId();
        this.productName = productPO.getProductName();
        this.categoryId = productPO.getCategory().getCatId();
        this.cateName = productPO.getCategory().getCatName();
        this.price = productPO.getPrice();
        this.thumbnail = productPO.getMainPic();
    }

    public Product(GoodsInfo goodsInfo) {
        this.productId = goodsInfo.getGoodsId();
        this.productName = goodsInfo.getGoodsName();
        this.categoryId = goodsInfo.getCategoryId();
        this.cateName = goodsInfo.getCateName();
        this.price = goodsInfo.getPrice();
        this.thumbnail = goodsInfo.getThumbnail();
    }
}
